#include "encounter.h"
#include "ui_encounter.h"
#include "menu.h"
#include <QPainter>
#include <QFont>
#include <QPixmap>
#include <QTimer>

int i=1;

encounter::encounter(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::encounter)
{
    ui->setupUi(this);
}

void encounter::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.setPen(Qt::black);//设置画笔颜色
    painter.setBrush(Qt::black);//设置填充颜色
    painter.drawRect(0,0,480,480);
    int x1=ui->qhframe->pos().x();
    int y1=ui->qhframe->pos().y();
    int x2=ui->p1frame->pos().x();
    int y2=ui->p1frame->pos().y();
    qh[0].load(":/resourse/0.png") ;
    qh[1].load(":/resourse/1.png") ;
    qh[2].load(":/resourse/2.png") ;
    qh[3].load(":/resourse/3.png") ;
    qh[4].load(":/resourse/4.png") ;
    qh[5].load(":/resourse/5.png") ;
    qh[6].load(":/resourse/6.png") ;
    qh[7].load(":/resourse/7.png") ;
    qh[8].load(":/resourse/8.png") ;
    qh[9].load(":/resourse/9.png") ;
    qh[10].load(":/resourse/10.png") ;
    qh[11].load(":/resourse/p1.png") ;
    QFont font1("Courier New",10);
    painter.setFont(font1);
    painter.setPen(Qt::red);
    painter.setBrush(Qt::red);
    painter.drawText(10,185,dialog[i]);
    if (i>=9)
    {
    painter.drawPixmap(x2,y2,ui->p1frame->width(),ui->p1frame->height(),qh[11]);
    }

    if (i==1||i==2||i==3)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[1]);
    }

    if (i==4)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[2]);
    }

    if (i==5)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[3]);
    }

    if (i==6)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[4]);
    }

    if (i==7)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[5]);
    }

    if (i==8)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[6]);
    }

    if (i==9||i==10)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[7]);
    }

    if (i==11)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[8]);
    }

    if (i==12||i==13||i==14)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[9]);
    }

    if (i==15)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[8]);
    }

    if (i==16||i==17)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[0]);
    }

    if (i==18||i==19)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[10]);
    }

    if (i==20)
    {
        this->close();
        Game1 *g1 =new Game1();
        g1->show();
    }

}

void encounter::on_nextpushButton_clicked()
{
    i++;
    update();
}

encounter::~encounter()
{
    delete ui;
}
